//原文链接：https://blog.csdn.net/ITSOK_123/article/details/123891429
//暴力求解
class Solution {
public:
    vector<int> sortedSquares(vector<int>& A) {
        for (int i = 0; i < A.size(); i++) {
            A[i] *= A[i];
        }
        sort(A.begin(), A.end()); // 快速排序
        return A;
    }
};

//双指针法
class Solution {
public:
    vector<int> sortedSquares(vector<int>& A) {
        int k=A.size()-1;
        vector<int> result(k+1,0);
        int i=0,j=k;
        while(i<=j){
            if(A[i]*A[i]<A[j]*A[j]){
                result[k--]=A[j]*A[j];
                j--;
            }
            else{
                result[k--]=A[i]*A[i];
                i++;
            } 
        }
        return result;
    }
};
